﻿using UnityEngine;


namespace RStudio.Elevator
{
    /// <summary>
    /// 封装|电梯组件
    /// </summary>
    public class ElevatorComponent : MonoBehaviour
    {
        [Tooltip("目标信息")] public Transform _Transform;
        [Tooltip("门禁信息")] public Transform _DoorL;
        [Tooltip("门禁信息")] public Transform _DoorR;


        /// <summary>
        /// 索引唯一编号
        /// </summary>
        public string Key { get; set; }

        /// <summary>
        /// 驱动
        /// </summary>
        public ElevatorDriven Driven { get; private set; }

        /// <summary>
        /// 队列
        /// </summary>
        public ElevatorQueue Queue { get; private set; }

        /// <summary>
        /// 楼层配置
        /// </summary>
        public PlanElevator Plan { get; private set; }

        /// <summary>
        /// 电梯参数
        /// </summary>
        public ElevatorDetail Detail { get; private set; }



        /// <summary>
        /// 
        /// </summary>
        /// <param name="name">唯一标识符</param>
        /// <param name="detail">电梯参数</param>
        /// <param name="plan">楼层参数</param>
        public ElevatorComponent Init(string name, PlanElevator plan, ElevatorDetail detail = null)
        {
            this.Key = name;
            this.Detail = detail ?? new ElevatorDetail(name);
            this.Plan = plan;
            this.Queue = new ElevatorQueue(this);
            this.Driven = new ElevatorDriven(this);

            ElevatorModuleCenter center = ElevatorModuleCenter.Instance;
            center.ElevatorModuleDetail.Register(this.Detail);
            center.ElevatorModulePlan.Register(this.Plan);
            center.ElevatorModuleCall.Register(this.Queue);
            center.ElevatorModuleDriven.Register(this.Driven);

            return this;
        }

        /// <summary>
        /// 绑定|基础参数
        /// </summary>
        /// <param name="name"></param>
        /// <returns>
        /// 你必须确认已注册情况下，可选择此方法。
        /// </returns>
        public ElevatorComponent Bind(string name)
        {
            this.Key = name;

            ElevatorModuleCenter center = ElevatorModuleCenter.Instance;
            this.Detail = center.ElevatorModuleDetail.Get(name);
            this.Plan = center.ElevatorModulePlan.Get(name);
            this.Queue = center.ElevatorModuleCall.Get(name);
            this.Driven = center.ElevatorModuleDriven.Get(name);

            return this;
        }
    }
}
